﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PhoneBook
{
     /**
     * Class representing a contact.
     * A contact is identified by a person and holds telephone numbers (home number, office number and cellular number).
     * @author Occello Audrey
     * 
     * Addition of an URL for contact picture
     * @author Mickael GOUET
     */
    public class Contact : IComparable<Contact> {

	    private Person person;
	    private String homenum;
	    private String officenum;
	    private String cellnum;
	    private String pictureurl;
        
	    /**
	     * The person (p) first name and last name are mandatory.
	     * @param p a person.
	     * @param hn a home number.
	     * @param on a office number.
	     * @param cn a cellular number.
	     */
	    public Contact(Person p, String hn, String on, String cn, String pu){
	  	    person = p;
	  	    setHomenum(hn);
	        setOfficenum(on);
	  	    setCellnum(cn);
	  	    setPictureurl(pu);
	    }
    	
	    /**
	     * Two contacts are identical if they are associated with the same person.
	     */
	    public int CompareTo(Contact c) {
		    return this.getPerson().CompareTo(c.getPerson());
	    }
    	
	    /**
	     * Two contacts are identical if they are associated with the same person.
	     */	
	    public Boolean equals(Object o) {
		    if (o is Contact) return this.getPerson().Equals(((Contact)o).getPerson());
		    else return false;
	    }
    	
	    public Person getPerson() {
		    return person;
	    }

	    public void setHomenum(String homenum) {
		    this.homenum = homenum;
	    }

	    public String getHomenum() {
		    return homenum;
	    }

	    public void setOfficenum(String officenum) {
		    this.officenum = officenum;
	    }

	    public String getOfficenum() {
		    return officenum;
	    }

	    public void setCellnum(String cellnum) {
		    this.cellnum = cellnum;
	    }

	    public String getCellnum() {
		    return cellnum;
	    }
    	
        public void setPictureurl(String pictureurl) {
            this.pictureurl = pictureurl;
        }

        public String getPictureurl() {
            return pictureurl;
        }
    	
	    /**
	     * Return the person identity concatenated to the phone numbers.
	     */
	    public override String ToString() {
		    String s = person.ToString() +"\n";
		    s += ((homenum=="")?"n/a":homenum) +"\n";
		    s += ((officenum=="")?"n/a":officenum) +"\n";
		    s += ((cellnum=="")?"n/a":cellnum) +"\n";
		    s += ((pictureurl=="")?"n/a":pictureurl) +"\n";
		    return s;
	    }
    }
}
